package com.gameserver;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;

public class PlayerSocketRunnable implements Runnable {

	Socket socket;
	String message;
	BufferedReader input;
	PrintWriter output;
	
	public PlayerSocketRunnable(Socket playerSocket)
	{
		socket = playerSocket;
		try {
			input = new BufferedReader(
					new InputStreamReader(socket.getInputStream()));
			output  = new PrintWriter(
					new OutputStreamWriter(socket.getOutputStream()));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		message = null;
	}
	
	@Override
	public void run() {	
		System.out.println("Player Socket Run");
		while(socket.isConnected())
		{
			if (message == null)
			{
				try {
					message = input.readLine();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
			}
			}
		}
		System.out.println("Player Socket Closed");
	}
	
	public void clearMessage()
	{
		this.message = null;
	}

}
